package com.weedsdream.function

import androidx.lifecycle.lifecycleScope
import com.weedsdream.BaseActivity
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import kotlin.coroutines.CoroutineContext

/**在指定协程上下文中执行任务
 * @param context 协程上下文
 * @param func 任务逻辑
 * @return 协程任务Job*/
fun inCoroutine(
    context: CoroutineContext = Dispatchers.Main, func: suspend CoroutineScope. () -> Unit
) = BaseActivity.activity.lifecycleScope.launch { withContext(context) { func() } }